package com.oa.co.service.impl;
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 */

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oa.co.bo.ScheduleBo;
import com.oa.co.common.PageVo;
import com.oa.co.common.R;
import com.oa.co.mapper.ScheduleMapper;
import com.oa.co.pojo.Schedule;
import com.oa.co.pojo.User;
import com.oa.co.service.ScheduleService;
import com.oa.co.vo.ScheduleBarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sunXuDong
 * @data 2023/5/4
 */
@Service("scheduleService")
public class ScheduleServiceImpl implements ScheduleService {
    @Autowired
    private ScheduleMapper scheduleMapper;

    @Override
    public R add(Schedule schedule) {
        return scheduleMapper.add(schedule) == 1 ? R.ok() : R.error();
    }

    @Override
    public Schedule queryId(String d_id) {
        return scheduleMapper.queryId(d_id);
    }

    @Override
    public Integer del(String d_id) {
        return scheduleMapper.del(d_id);
    }

    @Override
    public PageVo queryPage(Integer page, Integer limit, String d_id,Integer d_code,String applicant) {
        PageHelper.startPage(page,limit);
        List<Schedule> schedules = scheduleMapper.queryPage(d_id,d_code,applicant);

        PageInfo<Schedule> pageInfo = new PageInfo<>(schedules);
        PageVo<Schedule> pageVo = new PageVo<>(0,"---",pageInfo.getTotal(),pageInfo.getList());

        return pageVo;
    }

    @Override
    public R bar(User user) {
        String username ="";
        if (user.getT_id()==12){
            username = user.getUsername();
        }

        List<ScheduleBarVo> list = scheduleMapper.bar(username);
        return R.ok().data("map",list);
    }

    @Override
    public R pie(User user) {
        String username ="";
        if (user.getT_id()==12){
            username = user.getUsername();
        }


        List<ScheduleBarVo> list = scheduleMapper.pie(username);

        return R.ok().data("map",list);

    }

    @Override
    public PageInfo<ScheduleBo> scheduleBo(Integer page, Integer limit, String d_id, Integer d_code, String applicant) {
        if(page!=null&&limit!=null){
            PageHelper.startPage(page,limit);

            List<ScheduleBo> students =  scheduleMapper.findStudentsByCondition(d_id,d_code,applicant);
            //把查询结果封装在 pageInfo 对象中  这个对象就是之前 咱们自己封装的 Page  里面有 分页信息 可以点进去看下
            PageInfo<ScheduleBo> pagedata = new PageInfo<>(students);
            System.out.println(1+"---------------"+pagedata.getList());
            return pagedata;
        }else{

            List<ScheduleBo> students =  scheduleMapper.findStudentsByCondition(d_id,d_code,applicant);
            //把查询结果封装在 pageInfo 对象中  这个对象就是之前 咱们自己封装的 Page  里面有 分页信息 可以点进去看下

            PageInfo<ScheduleBo> pagedata = new PageInfo<>(students);

            return pagedata;
        }
    }

    @Override
    public R eaa(String d_id, Integer d_code) {
        Integer update = scheduleMapper.eaa(d_id,d_code);
        if (update==1){
            if (d_code==7){
                return R.ok().message("审核通过操作成功");
            }
            return R.ok().message("驳回成功");
        }
        return R.error();
    }
}
